#include <string.h>
#include <stdio.h>
class Texture {
	public:
		AUX_RGBImageRec *Load_Bitmap(const char * filename);
		int LoadGLTexture(int nrtex);
		void BindTexture(int tex);
		void ReleaseTexture();
		GLuint rt();
	private:
		GLuint *textures;

};

void ReleaseTexture() {

	//glDeleteTextures(3, textures);
}

AUX_RGBImageRec *Texture::Load_Bitmap(const char * filename) {
	FILE *file=NULL;									

	if (!filename)										
	{
		return NULL;									
	}

	file=fopen(filename,"r");							
	if (file) {
		fclose(file);						
		return auxDIBImageLoad(filename);
	}

	return NULL;
}

int Texture::LoadGLTexture(int nrtex) {
	textures = new GLuint[nrtex];
	int status=FALSE;
	
	AUX_RGBImageRec *TextureImage[1];
	memset(TextureImage,0,sizeof(void *)*1);


	for(int i = 0; i < nrtex; i++) {	
		if (TextureImage[0]=Load_Bitmap("Data/NeHe.bmp")) {
			status=TRUE;
			glGenTextures(1, &textures[i]);
			glBindTexture(GL_TEXTURE_2D, textures[i]);
			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		}
	

	if (TextureImage[0]) {
		if (TextureImage[0]->data) {
			free(TextureImage[0]->data);		
		}
		free(TextureImage[0]);							
	}
	}
	return status;		
}

void Texture::BindTexture(int tex) {
	
}

GLuint Texture::rt() {
	return *textures;
}